<!DOCTYPE html>
<html lang="en">

<head>
    <title>表格练习</title>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <script src="./vue.js"></script>
    <style>
        #app {
            width: 600px;
            margin: 10px auto;
        }

        .tb {
            border-collapse: collapse;
            width: 100%;
        }

        .tb th {
            background-color: #0094ff;
            color: white;
        }

        .tb td,
        .tb th {
            padding: 5px;
            border: 1px solid black;
            text-align: center;
        }

        .add {
            padding: 5px;
            border: 1px solid black;
            margin-bottom: 10px;
        }
    </style>
</head>

<body>
    <div id="app">
        <table class="tb">
            <tr>
                <th>编号</th>
                <th>品牌名称</th>
                <th>创立时间</th>
                <th>操作</th>
            </tr>
            <tr v-for="(item, index) in items" :key="item.id">
                <td>{{item.id}}</td>
                <td>{{item.name}}</td>
                <td>{{item.time}}</td>
                <td>
                    <button @click='del(item.id)'> 删除</button>
                </td>
            </tr>
            <tr v-if="items.length==0">
                <td colspan="4">没有数据咯~</td>
            </tr>
        </table>
        <div :class="{hide:true}"></div>
    </div>
    <script>
        const vm = new Vue({
            el: '#app',
            data: {
                hide: true,
                items: [
                    {
                        id: 1001,
                        name: '范思哲',
                        time: 2017 - 07 - 06
                    },
                    {
                        id: 1002,
                        name: '爱马仕',
                        time: 2017 - 07 - 06
                    },
                    {
                        id: 1003,
                        name: '360',
                        time: 2017 - 07 - 06
                    },
                ]
            },
            methods: {
                del(id) {
                    let index;
                    this.items.forEach((item, idx) => {
                        if (item.id == id) {
                            index = idx;
                        }
                    });
                    this.items.splice(index, 1);
                }
            },
        });
    </script>
</body>

</html>